<?php

/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\grid\GridView;
use app\models\ChargeCashDeal;
use yii\data\ActiveDataProvider;

$dataProvider = new ActiveDataProvider([
    'query' => ChargeCashDeal::find()->select(['id','money','status','member_id','approve_dt','reg_dt'])->where([
      'type' => ChargeCashDeal::TYPE_CASH,
      'member_id'=>Yii::$app->user->getId()
      ])->with('member'),
    'pagination' => [
        'pageSize' => 20,
    ],
]);
$this->title = '提现记录';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="page-title">
  <div>
    <h1><i class="fa fa-money"></i> 提现记录</h1>
  </div>
</div>

<div class='card'>
  <?php
  //如何提前加载资源
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
  'header'=>'序号',
  'class' => 'yii\grid\SerialColumn'
],
/*'member.opencardbank',
'member.bankcardid',*/
[
  'header'=>'提现时间',
  'content'=>function ($model, $key, $index, $column) {
    return $model->reg_dt;
  }
],
[
  'header'=>'提现金额',
  'content'=>function ($model, $key, $index, $column) {
    $output='<span class="data_carriage" opencardbank="';
    $output.=$model->member->opencardbank;
    $output.='" bankcardid="';
    $output.=$model->member->bankcardid;
    $output.='" status="';
    $output.=$model->status;
    $output.='">';
    $output.=number_format($model->money,2);
    $output.='</span>';
    return $output;
  },
],
[
    'class' => 'yii\grid\ActionColumn',
    'header'=>'状态',
    'template'=>'{approve}',
    'buttons'=>[
        'approve'=> function ($url, $model, $key) {
          if($model->status==ChargeCashDeal::STATUS_PROVED){
            return '成功 <i class="fa fa-lg fa-info-circle alert-info info_tixian" style="cursor:pointer;"></i>';
          }else if($model->status==ChargeCashDeal::STATUS_UNPROVED){
            return '失败 <i class="fa fa-lg fa-info-circle alert-danger info_tixian" style="cursor:pointer;"></i>';
          }else if($model->status==ChargeCashDeal::STATUS_REGISTER){
            return '待审核 <i class="fa fa-lg fa-info-circle alert-info info_tixian" style="cursor:pointer;"></i>';
          }
          else if($model->status==ChargeCashDeal::STATUS_DISCARD){
            return '作废 <i class="fa fa-lg fa-info-circle alert-danger info_tixian" style="cursor:pointer;"></i>';
          }
        },
    ],
        // you may configure additional properties here
],

// 更复杂的列数据
/*[
    'class' => 'yii\grid\DataColumn', //由于是默认类型，可以省略
    'value' => function ($data) {
        return $data->name; // 如果是数组数据则为 $data['name'] ，例如，使用 SqlDataProvider 的情形。
    },
],*/
],

]);
?>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header btn-warning">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel"><i class="fa fa-legal"></i> 提现详情</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12">
            <!--div class="card"-->
            <section class="invoice">
              <div class="row">
                <div class="col-xs-12">
                  <h3><i id='reg_status_icon' class="fa fa-check-circle alert-info"></i> <span id='reg_status_text'>成功</span></h3>
                </div>
              </div>
              <div class="row invoice-info" style='padding:0 10px;'>
                <table class='table'>
                  <tr><td><b>提现银行名称</b></td><td><b id='reg_opencardbank'></b></td></tr>
                  <tr><td><b>银行卡号</b></td><td><b id='reg_bankcardid'></b></td></tr>
                  <tr><td><b>提现金额</b></td><td><span id='reg_money'></span></td></tr>
                  <tr><td><b>提现时间</b></td><td><span id='reg_date'></span></td></tr>
                </table>
              </div>
            </section>
            <!--/div-->
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-warning" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>

<?php $this->beginBlock('info-js') ?>

$(document).ready(function() {
  //审核提现
  $('.info_tixian').click(function(){
    var $row=$(this).parents('tr');
    var datakey = $row.attr('data-key');
    var $date=$row.find('td:eq(1)');
    var $carriage=$row.find('td:eq(2)').find('.data_carriage');

    $('#reg_date').text($date.text());
    $('#reg_money').text($carriage.text());
    $('#reg_opencardbank').text($carriage.attr('opencardbank'));
    $('#reg_bankcardid').text($carriage.attr('bankcardid'));

    if(0==$carriage.attr('status')){
      $('#reg_status_icon').prop('class','fa fa-hourglass alert-info');
      $('#reg_status_text').text('待审核');
    }else if(1==$carriage.attr('status')){
      $('#reg_status_icon').prop('class','fa fa-check-circle alert-info');
      $('#reg_status_text').text('成功');
    }else if(2==$carriage.attr('status')){
      $('#reg_status_icon').prop('class','fa fa-times-circle alert-danger');
      $('#reg_status_text').text('失败');
    }else if(3==$carriage.attr('status')){
      $('#reg_status_icon').prop('class','fa fa-thumbs-down alert-danger');
      $('#reg_status_text').text('作废');
    }

    $('#myModal').attr('data-key',datakey);
    $('#myModal').modal();
  });

});

<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['info-js'],\yii\web\View::POS_END); ?>
